# 东方财富网 https://data.eastmoney.com/yzxdr
import requests
import json
import time
import random

cookies = {
    'qgqp_b_id': '0b48e3bc368c61151376959a41521373',
    'st_si': '62024988744053',
    'websitepoptg_show_time': '1698713183991',
    'st_asi': 'delete',
    'st_pvi': '65827667859447',
    'st_sp': '2023-10-31%2008%3A46%3A23',
    'st_inirUrl': 'https%3A%2F%2Fcn.bing.com%2F',
    'st_sn': '11',
    'st_psi': '20231115144631752-113300304206-9726283679',
    'JSESSIONID': 'EB7E8565AE2A85A41EBDA0B2DFFDBF23',
}

headers = {
    'Accept': '*/*',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    # 'Cookie': 'qgqp_b_id=0b48e3bc368c61151376959a41521373; st_si=62024988744053; websitepoptg_show_time=1698713183991; st_asi=delete; st_pvi=65827667859447; st_sp=2023-10-31%2008%3A46%3A23; st_inirUrl=https%3A%2F%2Fcn.bing.com%2F; st_sn=11; st_psi=20231115144631752-113300304206-9726283679; JSESSIONID=EB7E8565AE2A85A41EBDA0B2DFFDBF23',
    'Pragma': 'no-cache',
    'Referer': 'https://data.eastmoney.com/yzxdr',
    'Sec-Fetch-Dest': 'script',
    'Sec-Fetch-Mode': 'no-cors',
    'Sec-Fetch-Site': 'same-site',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
    'sec-ch-ua': '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}
for i in range(1,100):
    url = f'https://datacenter-web.eastmoney.com/api/data/v1/get?callback=jQuery1123026305265990722604_1700030791682&sortColumns=NOTICEDATE&sortTypes=-1&pageSize=50&pageNumber={i}&columns=ALL&token=894050c76af8597a853f5b408b759f5d&reportName=RPTA_WEB_YZXDRINDEX&filter=(ENDDATE%3D%272023-09-30%27)'
    response = requests.get(
        url=url,
        cookies=cookies,
        headers=headers,
    ).text
    print(response)
    parse_data = "{"+response.split('({')[1].split(");")[0]
    json_data = json.loads(parse_data)
    print("----------第{}页数据：".format(i))
    for index,item in enumerate(json_data['result']['data']):
        print(item)
    random_number = random.randint(1, 3)

    time.sleep(random_number)

